11516 - WiFi (Binary search + greedy)
[andmenj-acm.git] / 11518 - Dominos 2 / d.cpp
blobf1e126072216f119289c3a300fe4be8364a64517
1 /*
2 Problem: 11518 - Dominos 2
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 Accepted
7 */
9 using namespace std;
10 #include <algorithm>
11 #include <iostream>
12 #include <iterator>
13 #include <sstream>
14 #include <fstream>
15 #include <cassert>
16 #include <climits>
17 #include <cstdlib>
18 #include <cstring>
19 #include <string>
20 #include <cstdio>
21 #include <vector>
22 #include <cmath>
23 #include <queue>
24 #include <deque>
25 #include <stack>
26 #include <map>
27 #include <set>
29 #define D(x) cout << #x " is " << x << endl
31 const int N = 10001;
33 vector<int> g[N];
34 bool dead[N];
35 int ans;
37 void shoot(int u){
38 if (dead[u]) return;
40 ans++;
41 dead[u] = true;
43 for (int i=0; i<g[u].size(); ++i) shoot(g[u][i]);
46 int main(){
47 int c;
48 for (cin >> c; c--; cout << ans << endl){
49 int n, m, l; cin >> n >> m >> l;
50 for (int i=0; i<=n; ++i){
51 g[i].clear();
52 dead[i] = false;
54 while(m--){
55 int u, v;
56 cin >> u >> v;
57 g[u].push_back(v);
60 ans = 0;
61 while (l--){
62 int u;
63 cin >> u;
64 shoot(u);
68 return 0;